<include file="public:header" />
<!--微信推送管理--> 

<link rel="stylesheet" type="text/css" href="__STATIC__/weixin/assets/sell/baseui/css/amazeui.css"/>
<link rel="stylesheet" type="text/css" href="__STATIC__/weixin/assets/sell/baseui/css/admin.css" />
<link rel="stylesheet" type="text/css" href="__STATIC__/weixin/assets/sell/css/style.css"/>



<!--[if (gte IE 9)|!(IE)]><!-->
	<script type="text/javascript" src="//cdn.bootcss.com/jquery/2.2.2/jquery.min.js"></script>
	<script type="text/javascript" src="//cdn.bootcss.com/fastclick/1.0.6/fastclick.min.js"></script>
  	<script>$(function() {FastClick.attach(document.body);});</script>
<!--<![endif]-->

<!--[if lte IE 8 ]>
	<script type="text/javascript" src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
	<script type="text/javascript" src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
	<script type="text/javascript" src="__STATIC__/weixin/assets/sell/baseui/js/amazeui.ie8polyfill.min.js"></script>
<![endif]-->

<script type="text/javascript" src="//cdn.bootcss.com/amazeui/2.7.2/js/amazeui.min.js"></script>

<link rel="stylesheet" href="__STATIC__/weixin/assets/sell/css/wxmaterial.css">
<script src="__STATIC__/weixin/assets/sell/js/wookmark.js"></script>

<?php if($isMubanID==false ) { 
?>
	<font color="red"> 注意模板ID未配置影响发送：</font> <a href='index.php?m=Admin&c=Weixin&a=wxauth' >立即配置</a>
	<script>
	
	</script>
<?php }?>
<div class="am-modal am-modal-alert" tabindex="-1" id="fq_alert">
  <div class="am-modal-dialog">
    <div class="am-modal-hd" id="fq_alert_title"></div>
    <div class="am-modal-bd" id="fq_alert_info">
    </div>
    <div class="am-modal-footer">
      <span class="am-modal-btn">确定</span>
    </div>
  </div>
</div>

<div class="am-modal am-modal-confirm" tabindex="-1" id="fq_confirm">
  <div class="am-modal-dialog">
    <div class="am-modal-hd" id="fq_confirm_title"></div>
    <div class="am-modal-bd" id="fq_confirm_info"></div>
    <div class="am-modal-footer">
      <span class="am-modal-btn" data-am-modal-confirm>确定</span>
    </div>
  </div>
</div>

<div class="am-modal am-modal-confirm" tabindex="-1" id="fq_true_confirm">
  <div class="am-modal-dialog">
    <div class="am-modal-hd" id="fq_true_confirm_title"></div>
    <div class="am-modal-bd" id="fq_true_confirm_info"></div>
    <div class="am-modal-footer">
		<span class="am-modal-btn" data-am-modal-confirm>确定</span>
		<span class="am-modal-btn" data-am-modal-cancel class="cancel">取消</span>
    </div>
  </div>
</div>

<!-- content start -->



	<div class="admin-content">



		<div class="admin-content-body">



			<div class="am-margin-top-sm am-margin-left">



				<strong class="am-text-primary am-text-lg">消息推送</strong> / <small>Message pushing</small>



			</div>



			<div class="am-margin">



			



				<div class="am-article-lead am-margin-vertical-xs am-margin-bottom ">
					<span class="am-icon-bullhorn" style="margin-left:-2px;"></span> <strong>特别提示：</strong><strong class="am-text-danger">该功能并非公众号群发，不占用公众号每月4次群发额度且可以无限次发送，但该操作比较耗时，粉丝量较大的用户需要耐心等待（非常不建议滥用该功能  <a target="_blank" href="#">点击查看注意事项</a>）！</strong>
				</div>



			



				<div class="am-tabs" data-am-tabs="{noSwipe: 1}">



					<ul class="am-tabs-nav am-nav am-nav-tabs">



						<li class="am-active"><a href="#message" class="newPush">新建推送消息</a></li>



						<li class="" style="display:none"><a class="success" href="#allSend">已发送</a></li>



					</ul>



					<div class="am-tabs-bd">



						<div class="am-tab-panel am-active am-in" id="message" style="padding:18px 15px;">



							<div class="am-margin-left-xs am-text-center show_set am-hide">



								<span class="am-badge am-badge-default am-radius am-text-center" style="margin-left: 20px;">您尚未设置行业，请点击设置生成推送模板</span>



								<br/>



								<button type="button" class="am-btn am-btn-secondary am-margin-top-sm set_trade">设置行业</button>



							</div>



							<div class="am-show ">

								

								<div class="am-form-group am-cf">



									<label class="am-u-md-2 am-form-label pos">功能开启</label>



									<div class="am-input-group am-u-md-6">

										<label class="am-checkbox">

									    	<input type="checkbox" value="" data-am-ucheck id="isPush" {$hour24}> 24小时内已推送过的会员不再推送 <i class="am-icon-spinner am-icon-spin tips am-hide"></i>

									    </label>

									</div>



									<div class="am-u-md-4 am-padding-top-xs"></div>



								</div>	



								<div class="am-form-group am-cf">



									<label class="am-u-md-2 am-form-label pos">模板选择</label>



									<div class="am-input-group am-u-md-6">



										<select data-am-selected id="tpl">



											<option value="1" selected>待处理通知</option>



											<option value="2" >即将过期提醒</option>



										</select>



										<button type="button" class="am-btn am-btn-secondary am-margin-left-sm update" style="display:none;">重新获取模板</button>
								<button type="button" class="am-btn am-btn-secondary am-margin-left-sm funsupdate" >同步微信平台粉丝(当前本地：{$localuserCount})</button>


									</div>



									<div class="am-u-md-4 am-padding-top-xs"></div>



								</div>



								<div class="am-form-group am-cf">



									<label class="am-u-md-2 am-form-label pos">分组选择</label>



									<div class="am-input-group am-u-md-6">				



										<select data-am-selected="{maxHeight:250}" class="tags"> 
											<option value="-1">全部分组</option> 
											<volist name="groupList" id="vo">
											<option value="{$vo.id}">{$vo.name}-{$vo.count}</option>
											</volist> 
										</select>



										<!--<span class="am-inline-block am-padding-left-sm am-text-sm" style="position:relative;top:3px;display:none;">分组人数：</span><span class="userNum am-text-sm am-margin-right-sm" style="position:relative;top:3px;">443（实际推送人数：442）</span> <span class="tip" style="position:relative;top:3px;display:none"><i class="am-icon-spinner am-icon-spin"></i></span>-->



									</div>



									<div class="am-u-md-4 am-padding-top-xs"></div>



								</div>


								<!--
								<div class="am-form-group am-cf">



									<label class="am-u-md-2 am-form-label pos">分组成员</label>



									<div class="am-input-group am-u-md-6">



										<select data-am-selected="{maxHeight:250}" id="userList">



											<option value="-1">全部成员</option>



										</select>



									</div>



									<div class="am-u-md-4 am-padding-top-xs"></div>



								</div>
								-->


								<div class="tpl1">



									<div class="am-form-group am-cf">



										<label class="am-u-md-2 am-form-label pos">活动地址</label>



										<div class="am-input-group am-u-md-6">



											<input type="text" class="am-form-field" id="url" value="http://demo.itaoke.org" />



										</div>



										<div class="am-u-md-4 am-padding-top-xs"></div>



									</div>



									<div class="am-form-group am-cf">



										<label class="am-u-md-2 am-form-label pos">标题</label>



										<div class="am-input-group am-u-md-6">



											<input type="text" class="am-form-field" id="title" value="" />



										</div>



										<div class="am-u-md-4 am-padding-top-xs"></div>



									</div>



									<div class="am-form-group am-cf">



										<label class="am-u-md-2 am-form-label pos">通知内容</label>



										<div class="am-input-group am-u-md-6">



											<input type="text" class="am-form-field" id="content" />



										</div>



										<div class="am-u-md-4 am-padding-top-xs"></div>



									</div>



									<div class="am-form-group am-cf">



										<label class="am-u-md-2 am-form-label pos">通知人</label>



										<div class="am-input-group am-u-md-6">



											<input type="text" class="am-form-field" id="send"  value="内部优惠券购物"/>



										</div>



										<div class="am-u-md-4 am-padding-top-xs"></div>



									</div>



								</div>



								<div class="tpl2">



									<div class="am-form-group am-cf">



										<label class="am-u-md-2 am-form-label pos">活动地址</label>



										<div class="am-input-group am-u-md-6">



											<input type="text" class="am-form-field" id="pastUrl" value="http://demo.itaoke.org" />



										</div>



										<div class="am-u-md-4 am-padding-top-xs"></div>



									</div>



									<div class="am-form-group am-cf">



										<label class="am-u-md-2 am-form-label pos">标题</label>



										<div class="am-input-group am-u-md-6">



											<input type="text" class="am-form-field" id="pastTitle" value="" />



										</div>



										<div class="am-u-md-4 am-padding-top-xs"></div>



									</div>



									<div class="am-form-group am-cf">



										<label class="am-u-md-2 am-form-label pos">过期事项</label>



										<div class="am-input-group am-u-md-6">



											<input type="text" class="am-form-field" id="matter" value="" />



										</div>



										<div class="am-u-md-4 am-padding-top-xs"></div>



									</div>



									<div class="am-form-group am-cf">



										<label class="am-u-md-2 am-form-label pos">即将过期时间</label>



										<div class="am-input-group am-u-md-6">



											<input type="text" class="am-form-field" id="past" value="" />



										</div>



										<div class="am-u-md-4 am-padding-top-xs"></div>



									</div>



								</div>



								<div class="am-form-group am-cf" style="margin:0;">



									<label class="am-u-md-2 am-form-label pos"></label>



									<div class="am-input-group am-u-md-6">



										<button id="preview" class="am-btn am-btn-success am-margin-right-xs" data-am-modal="{target: '#preview-alert'}">预&nbsp;&nbsp;览</button>



										<button id="push" class="am-btn am-btn-primary tpl1">推&nbsp;&nbsp;送 <span id="async" style="display:none;">（<span id="plan">0</span> / <span id="total"></span>）</span></button>



										<button id="push2" class="am-btn am-btn-primary tpl2" style="display:none;">推&nbsp;&nbsp;送 <span id="async2" style="display:none;">（<span id="plan2">0</span> / <span id="total2"></span>）</span></button>



									</div>



									<div class="am-u-md-4 am-padding-top-xs"></div>



								</div>	



							</div>



						</div>



						<div class="am-tab-panel " id="allSend">



						    <table class="am-table am-table-striped am-table-hover am-text-sm table">



						    	<thead>



						    		<th>标题</th>



						    		<th style="width:300px;">发送内容</th>



						    		<th class="am-text-center">其他发送内容</th>



						    		<th>推送链接</th>



						    		<th>通知人</th>



						    		<th class="am-text-center">推送组/成员</th>



						    		<th class="am-text-center">推送成功人数</th>



						    		<th class="am-text-center">推送失败人数</th>



						    		<th>推送时间</th>



						    		<th>操作</th>



						    	</thead>



						    	<tbody id="tbody">



						    		<tr>
							    			<td class="title1013">您好！您有天猫内部优惠券尚未领取，请及时查收！！</td>
							    			<td class="content1013"> 天猫爆款秒杀商品，绝对超值，速度戳进来抢购！手慢无！！！</td>
							    			<td class="am-text-center past1013"></td>
							    			<td class="url1013">http://aitaoke/16421605</td>
							    			<td class="send1013">内部优惠券购物</td>
							    			<td class="am-text-center">
							    				全部分组							    			</td>
							    			<td class="am-text-center">256</td>
							    			<td class="am-text-center">19</td>
							    			<td>
							    				2016.08.26 13:00							    			</td>
							    			<td>
							    				<button type="button" class="am-btn am-btn-primary am-text-sm am-radius reSend" data-tpl="1" data-id="1013">编辑发送</button>
							    			</td>
							    		</tr>   						    	</tbody>
						    </table>
						    <div class="am-text-center am-hide">暂无推送信息</div>
						    <ul class="am-pagination am-pagination-centered am-text-xs">    </ul>
						</div>
					</div>
				</div>
			</div>
		</div>
		<footer class="admin-content-footer">
	<hr>
	<p class="am-padding-left">淘优惠 微信淘客系统 版权所有  Copyright © 2004-2016 爱淘客(www.itaoke.org).All Rights Reserved</p>
</footer>



	</div>



	<style>



		.table tr th,.table tr td{



			vertical-align: middle !important;



		}



	</style>



<!-- content end -->	


<!-- 预览start -->



<div class="am-modal am-modal-alert" tabindex="-1" id="preview-alert">



	<div class="am-modal-dialog" id="previewBox">



		<div class="am-modal-hd previewHb">



			<strong>爱淘客优惠券购物</strong>



		</div>



		<div class="am-modal-bd previewHd">



			<div class="am-margin-horizontal-xs am-padding-top-sm am-padding-horizontal-sm am-text-left am-text-sm" style="background:#FFF;margin-top:24px;margin-bottom:24px;">



				<h4><span class="tpl1">待处理通知</span><span class="tpl2">即将过期提醒</span></h4>



				<span class="am-text-xs am-margin-bottom-sm am-block" style="color:#A9A7A7;">7月1日</span>



				



				<div class="tpl1">



					<span class="am-margin-bottom-sm am-block am-text-break" id="titleBox"></span>



					<div class="am-margin-bottom-sm">



						<span class="am-inline-block">通知内容：</span><span class="am-margin-bottom-sm am-text-break" id="contentBox"></span>



					</div>



					<div class="am-margin-bottom-sm">



						<span class="am-inline-block">通知人：</span><span id="sendBox" class="am-text-break"></span>



					</div>



					<div class="am-margin-bottom-sm">



						<span class="am-inline-block">通知时间：</span><span id="timeBox">2016年07月01日 12:00</span>



					</div>



				</div>



				<div class="tpl2">



					<span class="am-margin-bottom-sm am-block am-text-break" id="pastTitleBox"></span>



					<div class="am-margin-bottom-sm">



						<span class="am-inline-block">过期事项：</span><span class="am-margin-bottom-sm am-text-break" id="matterBox"></span>



					</div>



					<div class="am-margin-bottom-sm">



						<span class="am-inline-block">即将过期时间：</span><span class="am-margin-bottom-sm am-text-break" id="pastBox"></span>



					</div>



					<span class="am-block am-margin-bottom-sm am-text-break" id="pastRemarkBox"></span>



				</div>



				<span class="am-block am-margin-bottom-sm" id="remarkBox">发送TD，不再接收该消息</span>



				<div class="am-padding-vertical-sm detail">



					详情



				</div>



			</div>



		</div>



		<div class="am-modal-bd empty"></div>



		<div class="am-modal-footer">



			<button class="am-inline-block am-text-sm am-btn am-btn-default" style="margin-top:50px;" data-am-modal-close>退出预览</button>



		</div>



	</div>



</div>



<!-- 预览end -->
<!-- <div class="am-modal am-modal-alert" tabindex="-1" id="alert">
  	<div class="am-modal-dialog">
    	<div class="am-modal-hd" id="alert_title"></div>
    	<div class="am-modal-bd" id="alert_info"></div>
	    <div class="am-modal-footer">
	      	<span class="am-modal-btn">确定</span>
	    </div>
  	</div>
</div> -->

<div class="am-modal am-modal-confirm" tabindex="-1" id="alert">
  	<div class="am-modal-dialog">
    	<div class="am-modal-hd" id="alert_title"></div>
    <div class="am-modal-bd" id="alert_info"></div>
    <div class="am-modal-footer">
      	<span class="am-modal-btn" data-am-modal-confirm>确定</span>
    </div>
  </div>
</div>

<div class="am-modal am-modal-confirm" tabindex="-1" id="alert_2">
  	<div class="am-modal-dialog">
    	<div class="am-modal-hd" id="alert_2_title"></div>
    <div class="am-modal-bd" id="alert_2_info"></div>
    <div class="am-modal-footer">
      	<span class="am-modal-btn" data-am-modal-confirm>确定</span>
    </div>
  </div>
</div>



<div class="am-hide"> </div>					
</html>



<script>
	$('.tpl1').show();
	$('.tpl2').hide();
	//------------------>方法
	//填充内容
	function fill(id,value){
		$('#'+id+'Box').text(value);
	}
	//推送
	function pushTpl(arr,tpl,tplType,url,title,content,send,times,i,log_id,tagName,pushtime){
		var start = i*20;
		var end = (i+1)*20;
		var box = arr.slice(start,end);
		$.ajax({
			data:{"id":box,"tpl":tpl,"title":title,"content":content,"send":send,"url":url,"log_id":log_id,"tag":tagName,"tplType":tplType,"pushtime":pushtime},
			type:'post',
			dataType:'json',
			url:'index.php?m=Admin&c=Weixin&a=wxpushtemplate',
			success:function(res){
				if(res.status == 1){
					var id = res.id;
					var listLen = arr.length;
					var a = i+1;
					if(a*20 >= listLen){
						$('#plan,#fq_alert_plan').text(listLen);
					}else{
						$('#plan,#fq_alert_plan').text(a*20);
					}
					if(times > a){
						pushTpl(arr,tpl,tplType,url,title,content,send,times,a,id,tagName,pushtime);
					}else{
						$('#isPush').prop('disabled',false);
						$('#alert_info').text('推送完成');
						$('#alert').modal({onConfirm:function(){window.location.reload();}});
						$('#fq_alert').modal('close');
						$('#async').hide();
						$('#plan').text(0);
						$('#total').text('');
						$('#push').prop('disabled',false);
					}

				}else{
					$('#isPush').prop('disabled',false);
					$('#async').hide();
					$('#plan').text(0);
					$('#total').text('');
					$('#push').prop('disabled',false);
					$('#fq_alert').modal('close');
					$('#alert_2_info').text(res.info);
					$('#alert_2').modal({});
					return;
				}

			},

			complete:function(XMLHttpRequest,status){

				if(status == 'timeout'){

					pushTpl(arr,tpl,tplType,url,title,content,send,times,i,log_id,tagName,pushtime);

				}else if(XMLHttpRequest.status != 200){
					$('#isPush').prop('disabled',false);
					$('#fq_alert_info').text('网络连接错误，请稍后再试');
					$('#fq_alert').modal({});
					$('#async').hide();
					$('#plan').text(0);
					$('#total').text('');
					$('#push').prop('disabled',false);

				}

			}

		});

	}

	//推送2
	function pushTpl2(arr,tpl,tplType,url,title,matter,past,times,i,log_id,tagName,pushtime){

		var start = i*20;

		var end = (i+1)*20;

		var box = arr.slice(start,end);

		$.ajax({

			data:{"id":box,"tpl":tpl,"title":title,"matter":matter,"past":past,"url":url,"log_id":log_id,"tag":tagName,"tplType":tplType,"pushtime":pushtime},

			type:'post',

			dataType:'json',

			url:'index.php?m=Admin&c=Weixin&a=wxpushtemplatetwo',

			success:function(res){

				if(res.status == 1){

					var id = res.id;

					var a = i+1;

					var listLen = arr.length;

					if(a*20 >= listLen){

						$('#plan2').text(listLen);

					}else{

						$('#plan2').text(a*20);

					}

					if(times > a){

						pushTpl2(arr,tpl,tplType,url,title,matter,past,times,a,id,tagName,pushtime);

					}else{

						$('#isPush').prop('disabled',false);
						$('#fq_alert').modal('close');
						$('#alert').modal({onConfirm:function(){window.location.reload();}});
						$('#alert_info').text('推送完成');
						$('#async2').hide();
						$('#plan2').text(0);
						$('#total2').text('');
						$('#push2').prop('disabled',false);
					}

				}else{
					$('#isPush').prop('disabled',false);
					$('#async2').hide();
					$('#plan2').text(0);
					$('#total2').text('');
					$('#push2').prop('disabled',false);
					$('#fq_alert').modal('close');
					$('#alert_2_info').text(res.info);
					$('#alert_2').modal({});
					return;
				}

			},



			complete:function(XMLHttpRequest,status){

				if(status == 'timeout'){

					pushTpl(arr,tpl,tplType,url,title,content,send,times,i,log_id,tagName,pushtime);

				}else if(XMLHttpRequest.status != 200){

					$('#isPush').prop('disabled',false);

					$('#fq_alert_info').text('网络连接错误，请稍后再试');

					$('#fq_alert').modal({});

					$('#async2').hide();

					$('#plan2').text(0);

					$('#total2').text('');

					$('#push2').prop('disabled',false);

				}

			}

		});

	}

	function delspecial(val){
		var str = val;
		str = str.replace(/[\t]/," ");
		str = str.replace(/[\r\n]/," ");
		str = str.replace(/[\r]/," ");
		str = str.replace(/[\n]/," ");
		str = str.replace(/[\"]/,'"');
		str = str.replace(/[\']/,"'");
		return str;
	}

	//------------------>方法 end

	$(function(){

		//是否开启功能

		$('#isPush').click(function(){
			var type;
			if($(this).prop('checked') == true){
				type = 1;
			}else if($(this).prop('checked') == false){
				type = 0;
			}
			$('.tips').removeClass('am-hide');
			$.ajax({
				url:'/index.php?m=Admin&c=Weixin&a=wxsetwithin',
				type:'post',
				data:{"status":type},
				dataType:'json',
				success:function(res){
					if(res.status == -1){
						$('#fq_alert_info').text(res.info);
					}else if(res.status == 0){
						if(type == 1){
							$('#fq_alert_info').text('关闭功能失败，请稍后再试');
						}else{
							$('#fq_alert_info').text('开启功能失败，请稍后再试');
						}
					}else{
						if(type == 1){
							$('#fq_alert_info').text('开启功能成功');
						}else{
							$('#fq_alert_info').text('关闭功能成功');
						}
					}
				},

				complete:function(XMLHttpRequest,status){
					if(XMLHttpRequest.status != 200){
						if(type == 1){
							$('#test').prop('checked',false);
						}else{
							$('#test').prop('checked',true);
						}
						$('#fq_alert_info').text('网络连接错误，请稍后再试');
					}
					$('#fq_alert').modal({});
					$('.tips').addClass('am-hide');
				}
			});

		});

		//更新模板

		$('.update').click(function(){

			$(this).html('更新中 <i class="am-icon-spinner am-icon-pulse"></i>').prop('disabled',true);

			$.ajax({
				url:'/wxtemplate/settemplate.html',
				type:'post',
				success:function(res){
					if(res.status == 1){
						$('#fq_alert_info').text('更新成功');
					}else{
						$('#fq_alert_info').text(res.info);
					}
					$('#fq_alert').modal({});
				},
				complete:function(){
					$('.update').text('重新获取模板').attr('disabled',false);
				}
			});
		});
		//更新粉丝

		$('.funsupdate').click(function(){

			$(this).html('更新中 <i class="am-icon-spinner am-icon-pulse"></i>').prop('disabled',true);

			$.ajax({
				url:'/index.php?m=Admin&c=Weixin&a=wxreplayuser',
				type:'post',
				success:function(res){
					if(res.status == 1){
						$('#fq_alert_info').text('更新成功');
						$('.funsupdate').text('同步微信平台粉丝(当前本地：'+res.count+')');
					}else{
						$('#fq_alert_info').text(res.info);
					}
					$('#fq_alert').modal({});
					
				},
				complete:function(){
					$('.funsupdate').attr('disabled',false);
				}
			});
		});
		
		
		//预览内容填充及展示
		$('#preview').click(function(){
			var type = $('#tpl').val();
			if(type == 1){
				fill('title',$('#title').val());
				fill('send',$('#send').val());
				fill('content',$('#content').val());
			}else if(type == 2){
				fill('pastTitle',$('#pastTitle').val());
				fill('matter',$('#matter').val());
				fill('past',$('#past').val());
			}

		});
		//推送1
		$('#push').click(function(){
			var url = $.trim(delspecial($('#url').val()));
			if(url == ''){
				$('#fq_alert').modal({});
				$('#fq_alert_info').text('活动地址不能为空');
				return;
			}
			var title = $.trim(delspecial($('#title').val()));//标题
			if(title == ''){
				$('#fq_alert').modal({});
				$('#fq_alert_info').text('商品标题不能为空');
				return;
			}
			var content = $.trim(delspecial($('#content').val()));//发送内容
			if(content == ''){
				$('#fq_alert').modal({});
				$('#fq_alert_info').text('商品信息不能为空');
				return;
			}

			var send = $.trim(delspecial($('#send').val()));//发送人
			if(send == ''){
				$('#fq_alert').modal({});
				$('#fq_alert_info').text('消息通知人不能为空');
				return;
			}

			$(this).prop('disabled',true);
			$('#isPush').prop('disabled',true);
			var tag = $('.tags').val();//发送组
			var user = $('#userList').val();//单人发送
			$('#fq_alert_info').text('推送中，请勿关闭本页面,否则将导致消息发送终止');
			$('#fq_alert').modal({});
			$.ajax({
				type:'post',
				data:{"tag":tag,"uid":user,"tpl":1},
				dataType:'json',
				url:'index.php?m=Admin&c=Weixin&a=wxgetpushuser',
				success:function(data){
					if(data.status == 1){
						$('#fq_alert_info').html('推送中，请勿关闭本页面，否则将导致消息发送终止');
						var len = data.list.length;
						var times = Math.ceil(len/20);
						$('#async').show();
						$('#total').text(len);
						var tagName = data.tag; 
						pushTpl(data.list,data.tpl,1,url,title,content,send,times,0,0,tagName,data.pushtime);
					}else{
						$('#isPush').prop('disabled',false);
						$('#fq_alert_info').text(data.info);
						$('#fq_alert').modal({});
						$('#push').prop('disabled',false);
					}
				},
				complete:function(XMLHttpRequest,status){
					if(status == 'timeout'){
						$('#isPush').prop('disabled',false);
						$('#fq_alert_info').text('获取发送会员超时，请减少发送人数');
						$('#fq_alert').modal({});
						$('#push').prop('disabled',false);
					}else if(XMLHttpRequest.status != 200){
						$('#isPush').prop('disabled',false);
						$('#fq_alert_info').text('网络连接错误，请稍后再试');
						$('#fq_alert').modal({});
						$('#push').prop('disabled',false);

					}
				}

			})

		});

		//推送2
		$('#push2').click(function(){

			var url = $.trim(delspecial($('#pastUrl').val()));

			if(url == ''){

				$('#fq_alert').modal({});

				$('#fq_alert_info').text('活动地址不能为空');

				return;

			}

			var title = $.trim(delspecial($('#pastTitle').val()));//标题

			if(title == ''){

				$('#fq_alert').modal({});

				$('#fq_alert_info').text('标题不能为空');

				return;

			}

			var matter = $.trim(delspecial($('#matter').val()));//过期事项

			if(matter == ''){

				$('#fq_alert').modal({});

				$('#fq_alert_info').text('过期事项不能为空');

				return;

			}



			var past = $.trim(delspecial($('#past').val()));//过期时间

			if(past == ''){

				$('#fq_alert').modal({});

				$('#fq_alert_info').text('过期时间不能为空');

				return;

			}



			$(this).prop('disabled',true);



			var tag = $('.tags').val();//发送组



			var user = $('#userList').val();//单人发送



			$('#fq_alert_info').text('推送中，请勿关闭本页面,否则将导致消息发送终止');



			$('#fq_alert').modal({});



			$.ajax({



				type:'post',



				data:{"tag":tag,"uid":user,"tpl":2},



				dataType:'json',



				url:'index.php?m=Admin&c=Weixin&a=wxgetpushuser',



				success:function(data){



					if(data.status == 1){

						var len = data.list.length;

						var times = Math.ceil(len/20);

						$('#async2').show();

						$('#total2').text(len);

						var tagName = data.tag; 



						pushTpl2(data.list,data.tpl,2,url,title,matter,past,times,0,0,tagName,data.pushtime);



					}else{



						$('#isPush').prop('disabled',true);



						$('#fq_alert_info').text(data.info);



						$('#fq_alert').modal({});



						$('#push2').prop('disabled',false);



					}



					

				},

				complete:function(XMLHttpRequest,status){



					if(status == 'timeout'){



						$('#isPush').prop('disabled',false);



						$('#fq_alert_info').text('操作超时，请稍后再试');



						$('#fq_alert').modal({});



						$('#push').html('推&nbsp;&nbsp;送').prop('disabled',false);



					}else if(XMLHttpRequest.status != 200){



						$('#isPush').prop('disabled',false);



						$('#fq_alert_info').text('网络连接错误，请稍后再试');



						$('#fq_alert').modal({});



						$('#push').prop('disabled',false);

					}

				}

			})

		});





		$('#tpl').change(function(){



			var tpl = $(this).val();



			if(tpl == 1){



				$('.tpl1').show();



				$('.tpl2').hide();



			}else if(tpl == 2){



				$('.tpl1').hide();



				$('.tpl2').show();



			}else{



				$('#fq_alert').modal({});



				$('#fq_alert_info').text('请勿修改页面代码');



			}



		});







		//获取分组人数



		$('.tags').change(function(){

	$('#isPush').prop('disabled',false);

		/*
			var tagId = $(this).val();



			$('.tip').show();



			$('#isPush').prop('disabled',true);



			$.ajax({



				url:'/wxtemplate/getcount.html',



				data:{"tagId":tagId},



				dataType:'json',



				type:'post',



				success:function(data){



					$('.userNum').text(data.all+'（实际推送人数：'+data.count+'）');



					var html='<option value="-1">全部成员</option>';



					var len = data['tagUser'].length;



					if(tagId != -1){



						for(var i = 0;i < len ; i++){



							html += '<option value="'+data['tagUser'][i]['uid']+'">'+data['tagUser'][i]['nickname']+'</option>';



						}



					}

				

					$('#userList').html(html);



				},

				complete:function(XMLHttpRequest,status){



					if(XMLHttpRequest.status != 200){



						$('#fq_alert_info').text('网络连接错误，请稍后再试');



						$('#fq_alert').modal({});

	

					}



					$('.tip').hide();



					$('#isPush').prop('disabled',false);



				}



			});*/



		});





	//设置行业生成模板



		$('.set_trade').click(function(){



			$(this).html('设置中 <i class="am-icon-spinner am-icon-pulse"></i>').prop('disabled',true);



			$.ajax({



				type:'post',



				url:'/wxtemplate/setvocation.html',



				success:function(res){



					if(res.status == -1){



						$('#fq_alert').modal({});



						$('#fq_alert_info').text(res.info);



					}else if(res.status == 1){



						$('#fq_alert').modal({});



						$('#fq_alert_info').text(res.info);



						window.location.reload();



					}



				},

				complete:function(XMLHttpRequest,status){



					if(status == 'timeout'){



						$('#fq_alert_info').text('操作超时，请刷新页面');



						$('#fq_alert').modal({});



					}else if(XMLHttpRequest.status != 200){



						$('#fq_alert_info').text('网络连接错误，请稍后再试');



						$('#fq_alert').modal({});



					}



					$('.set_trade').text('设置行业').prop('disabled',false);



				}



			});



		});



		//重新编辑发送



		$('.reSend').click(function(){



			



			var tpl = $(this).attr('data-tpl');



			var id = $(this).attr('data-id');



			if(tpl == 1){



				$('.tpl1').show();



				$('.tpl2').hide();



				$('#tpl option').attr('selected',false);



				$('#tpl option[value=1]').attr('selected',true);



				//内容填充



				$('#send').val($('.send'+id).text());



				$('#url').val($('.url'+id).text());



				$('#content').val($('.content'+id).text())



				$('#title').val($('.title'+id).text());



			}else if(tpl == 2){



				$('.tpl2').show();



				$('.tpl1').hide();



				$('#tpl option').attr('selected',false);



				$('#tpl option[value=2]').attr('selected',true);



				//内容填充



				$('#pastUrl').val($('.url'+id).text());



				$('#past').val($('.past'+id).text());



				$('#pastTitle').val($('.title'+id).text());



				$('#matter').val($('.content'+id).text());



			}else{



				$('#fq_alert').modal({});



				$('#fq_alert_info').text('请勿修改页面代码');



				return false;



			}







			$('.newPush').click();



		});



















	});



	



</script>